package com.xyq.system.controller.exam;

import com.xyq.common.core.controller.BaseController;
import com.xyq.common.core.domain.Result;
import com.xyq.common.core.domain.TableDataInfo;
import com.xyq.system.domain.exam.dto.*;
import com.xyq.system.domain.exam.vo.ExamQuestionListVO;
import com.xyq.system.domain.exam.vo.ExamVO;
import com.xyq.system.service.exam.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {
    @Autowired
    private ExamService examService;
   // 获取竞赛列表
    @GetMapping("/list")
     public TableDataInfo list(ExamDTO examDTO){
        List<ExamVO> list = examService.list(examDTO) ;
        return  getTableList(list);
    }
   // 添加竞赛
    @PostMapping("/add")
    public Result add( @Validated  @RequestBody ExamAddDTO examAddDTO){

        Long  id = examService.add(examAddDTO);
           if( id <= 0 ){
               return Result.fail();
           }

        return Result.success(id.toString()) ;
    }
    // 为竞赛添加题目
    @PostMapping("/addQuestion")
    public Result addQuestion(@RequestBody @Validated ExamQuestionAddDTO examQuestionAddDTO){
        return toResult(examService.addQuestion(examQuestionAddDTO));
    }

    // 获取竞赛的详细信息
    @GetMapping("/getExamDetailById")
    public Result getExamDetailById( Long examId){

        return examService.getExamDetailById(examId);
    }
    // 编辑竞赛
    @PutMapping("/editExam")
    public Result editExam(@Validated  @RequestBody ExamEditDTO examEditDTO){

        return toResult(examService.editExam(examEditDTO));
    }
    @DeleteMapping("/deleteExam")
    public Result deleteExam(Long examId){
        return toResult(examService.deleteExam(examId));
    }

    // 删除竞赛里的题目
    @DeleteMapping("/deleteExamQuestion")
    public Result deleteExamQuestion(@Validated @RequestBody  ExamQuestionDeleteDTO examQuestionDeleteDTO){
        return toResult(examService.deleteExamQuestion(examQuestionDeleteDTO));
    }
    // 发布竞赛
    @PutMapping("/publishExam")
    public Result publishExam(Long examId){
        return toResult(examService.publishExam(examId));
    }

    // 撤销发布
    @PutMapping("/cancelPublishExam")
    public Result cancelPublishExam(Long examId){
        return toResult(examService.cancelPublishExam(examId));
    }

    //

}
